#include "clientadmin.h"

#include <string.h>
#include <stdio.h>

#include "StdTcp.h"
#define true 1
#define false 0

int ClientUserLoginRegistration(TcpC *c,Msg *m)
{
    printf("**************\n");
    printf("* 1.登录账户 *\n");
    printf("* 2.注册账户 *\n");
    printf("**************\n");
    memset(m,0,sizeof(Msg));
    printf("请输入你的选择:\n");
    int choice=0;
    scanf("%d",&choice);
    while(getchar()!='\n');
    if(choice==1)
    {
        printf("请输入你的账户ID:\n");
        scanf("%d",&m->mynameid);
        while(getchar()!='\n');
        printf("请输入你的账户密码:\n");
        memset(m->password,0,sizeof(m->password));
        scanf("%s",m->password);
        while(getchar()!='\n');
        m->operationflag=11;
        TcpClinetSend(c,m,sizeof(Msg));
        TcpClinetRecv(c,m,sizeof(Msg));
        if(m->operationflag==111)
        {
            printf("登录成功\n");
            return true;
        }
        else if(m->operationflag==1110)
        {
            printf("该账户在线，请重试\n");
            return false;
        }
        else 
        {
            printf("请检查账户ID和密码是否有误\n");
            return false;
        }
    }
    if(choice==2)
    {
        printf("请输入你的账户名字:\n");
        scanf("%s",m->myname);
        while(getchar()!='\n');
        char temp1[10]={0};
        char temp2[10]={0};
        printf("请输入你的账户密码:\n");
        scanf("%s",temp1);
        while(getchar()!='\n');
        printf("请再次输入你的账户密码:\n");
        scanf("%s",temp2);
        while(getchar()!='\n');
        if(strcmp(temp1,temp2)!=0)
        {
            printf("两次输入的密码不一致，请重新输入！\n");
            return false;
        }
        memset(m->password,0,sizeof(m->password));
        strcpy(m->password,temp1);
        m->operationflag=12;
        TcpClinetSend(c,m,sizeof(Msg));
        TcpClinetRecv(c,m,sizeof(Msg));
        if(m->operationflag==112)
        {
            printf("注册成功！\n");
            printf("你的账户名字是: %s\n",m->myname);
            printf("你的账户ID是: %d\n",m->mynameid);
            printf("你的账户密码是: %s\n",m->password);
            return false;
        }
        else
        {
            printf("注册失败！\n");
            return false;
        }
    }
    return false;
}




void Friends(TcpC *c, Msg *m,Admin *a)
{
    while(1)
    {
        printf("******************\n");
        printf("* 1.查看全部好友 *\n");              //21
        printf("* 2.查看在线好友 *\n");              //22
        printf("* 3.发消息       *\n");                   //23
        printf("* 4.查看好友申请 *\n");              //24
        printf("* 5.查看好友消息 *\n");              //25
        printf("* 6.添加好友     *\n");                 //26
        printf("* 7.删除好友     *\n");                 //27
        printf("* 8.返回上一级   *\n");               //28
        printf("******************\n");
        int choice=0;
        scanf("%d",&choice);
        while(getchar()!='\n');
        switch(choice)
        {
        case 1:
            m->operationflag=21;
            m->serial=a->serial;
            TcpClinetSend(c,m,sizeof(Msg));
            TcpClinetRecv(c,m,sizeof(Msg));
            if(m->operationflag==121)
            {
                printf("你的好友有:\n");
                printf("好友名字\t好友ID\n");
                int num=m->numflag;
                for(int i=0;i<num;i++)
                {
                    TcpClinetRecv(c,m,sizeof(Msg));
                    printf("%s\t\t%d\n",m->toname,m->tonameid);
                }   
            }
            break;
        case 2:
            m->operationflag=22;
            m->serial=a->serial;
            TcpClinetSend(c,m,sizeof(Msg));
            TcpClinetRecv(c,m,sizeof(Msg));
            if(m->operationflag==122)
            {
                printf("你的在线好友有:\n");
                printf("好友名字\t好友ID\n");
                int num=m->numflag;
                for(int i=0;i<num;i++)
                {
                    TcpClinetRecv(c,m,sizeof(Msg));
                    printf("%s\t\t%d\n",m->toname,m->tonameid);
                } 
            }

            break;
        case 3:
            memset(m,0,sizeof(Msg));
            m->operationflag=23;
            m->serial=a->serial;
            m->mynameid=a->mynameid;
            strcpy(m->myname,a->myname);
            printf("请输入你要发送的好友ID:\n");
            scanf("%d",&m->tonameid);
            while(getchar()!='\n');
            printf("请输入你要发送的信息:\n");
            scanf("%s",m->content);
            while(getchar()!='\n');
            TcpClinetSend(c,m,sizeof(Msg));
            TcpClinetRecv(c,m,sizeof(Msg));

            if(m->operationflag==123)
            {
                printf("发送成功\n");
            }
            else if(m->operationflag==1230)
            {
                printf("暂无该好友\n");
            }
            else
            {
                printf("发送失败\n");
            }
            break;
        case 4:
            memset(m,0,sizeof(Msg));
            m->operationflag=24;
            m->serial=a->serial;
            m->mynameid=a->mynameid;
            strcpy(m->myname,a->myname);
            TcpClinetSend(c,m,sizeof(Msg));
            TcpClinetRecv(c,m,sizeof(Msg));
            if(m->operationflag==124)
            {
                int num=m->numflag;
                if(num==0)
                {
                    printf("暂无好友申请\n");
                }
                for(int i=0;i<num;i++)
                {
                    TcpClinetRecv(c,m,sizeof(Msg));
                    printf("%s\t\t%d\n",m->toname,m->tonameid);
                    printf("申请加你为好友\n");
                    while(1)
                    {
                        printf("1.同意\n");
                        printf("2.不同意\n");
                        int choice=0;
                        scanf("%d",&choice);
                        while(getchar()!='\n');
                        if(choice==1)
                        {
                            m->operationflag=1241;
                            m->tonameid=m->tonameid;
                            TcpClinetSend(c,m,sizeof(Msg));
                            TcpClinetRecv(c,m,sizeof(Msg));
                            if(m->operationflag==12411)
                            {
                                printf("添加成功\n");
                            }
                            break;
                        }
                        else if(choice==2)
                        {
                            m->operationflag=1240;
                            m->tonameid=m->tonameid;
                            TcpClinetSend(c,m,sizeof(Msg));
                            TcpClinetRecv(c,m,sizeof(Msg));
                            if(m->operationflag!=12411)
                            {
                                printf("已拒绝\n");
                            }
                            break;
                        }
                        else
                            printf("输入错误，请重新输入！\n");
                    }
                }
            }
            
            break;
        case 5:
            memset(m,0,sizeof(Msg));
            m->operationflag=25;
            m->serial=a->serial;
            strcpy(m->myname,a->myname);
            m->mynameid=a->mynameid;
            TcpClinetSend(c,m,sizeof(Msg));
            TcpClinetRecv(c,m,sizeof(Msg));
            if(m->operationflag==125)
            {
                int num=m->numflag;
                if(num==0)
                {
                    printf("暂无好友消息\n");
                }
                for(int i=0;i<num;i++)
                {
                    TcpClinetRecv(c,m,sizeof(Msg));
                    printf("%s %d : %s\n",m->toname,m->tonameid,m->content);
                }
            }
            break;
        case 6:
            memset(m,0,sizeof(Msg));
            m->operationflag=26;
            m->serial=a->serial;
            strcpy(m->myname,a->myname);
            m->mynameid=a->mynameid;
            printf("请输入你要添加的好友ID:\n");
            scanf("%d",&m->tonameid);
            while(getchar()!='\n');
            TcpClinetSend(c,m,sizeof(Msg));
            TcpClinetRecv(c,m,sizeof(Msg));
            if(m->operationflag==126)
            {
                printf("等待对方同意\n");
            }
            if(m->operationflag==1260)
            {
                printf("不能添加自己为好友\n");
            }
            if(m->operationflag==1261)
            {
                printf("已有此好友\n");
            }
            if(m->operationflag==1262)
            {
                printf("查无此人\n");
            }
            if(m->operationflag==1263)
            {
                printf("重复发送\n");
            }
            break;
        case 7:
            memset(m,0,sizeof(Msg));
            m->operationflag=27;
            m->serial=a->serial;
            strcpy(m->myname,a->myname);
            m->mynameid=a->mynameid;
            printf("请输入你要删除的好友ID:\n");
            scanf("%d",&m->tonameid);
            while(getchar()!='\n');
            TcpClinetSend(c,m,sizeof(Msg));
            TcpClinetRecv(c,m,sizeof(Msg));
            if(m->operationflag==127)
            {
                printf("删除成功\n");
            }
            if(m->operationflag==1271)
            {
                printf("无此好友\n");
            }
            break;
        case 8:
            return;
            break;
        default:
            printf("输入错误，请重新输入！\n");
            break;
        }
    }
}

void GroupSetting(TcpC *c, Msg *m,Admin *a)
{
    memset(m,0,sizeof(Msg));
    m->operationflag=50;
    m->serial=a->serial;
    m->mynameid=a->mynameid;
    printf("请输入群聊ID:\n");
    scanf("%d",&m->groupid);
    while(getchar()!='\n');
    int groupid=m->groupid;
    TcpClinetSend(c,m,sizeof(Msg));
    TcpClinetRecv(c,m,sizeof(Msg));
    if(m->operationflag!=150)
    {
        printf("无此群聊\n");
        return;
    }

    while(1)
    {
        printf("*******************\n");
        printf("* 1.查看群成员    *\n");                  //30
        printf("* 2.发消息        *\n");                   //32
        printf("* 3.查看群聊消息  *\n");     
        printf("* 4.上传群文件    *\n") ;       //x
        printf("* 5.下载群文件    *\n");       //x
        printf("* 6.禁言          *\n");
        printf("* 7.解除禁言      *\n");
        printf("* 8.群聊拉人      *\n");
        printf("* 9.管理员设置    *\n");
        printf("* 10.群聊解散     *\n");       //x
        printf("* 11.退出群聊     *\n");        //x
        printf("* 12.群聊转让     *\n");
        printf("* 13.群聊踢人     *\n");
        printf("* 14.返回上一级   *\n");
        printf("*******************\n");
        printf("请输入你的选择:\n");
        int choice;
        scanf("%d",&choice);
        while(getchar()!='\n');
        switch(choice)
        {
            case 1:
                memset(m,0,sizeof(Msg));
                m->operationflag=51;
                m->groupid=groupid;
                TcpClinetSend(c,m,sizeof(Msg));
                TcpClinetRecv(c,m,sizeof(Msg));
                if(m->operationflag==151)
                {
                    printf("群成员名字\t群成员ID\n");
                    int num=m->numflag;
                    for(int i=0;i<num;i++)
                    {
                        TcpClinetRecv(c,m,sizeof(Msg));
                        printf("%s\t\t%d\n",m->toname,m->tonameid);
                    }
                }
                break;
            case 2:
                memset(m,0,sizeof(Msg));
                m->operationflag=52;
                m->mynameid=a->mynameid;
                m->serial=a->serial;
                strcpy(m->myname,a->myname);
                m->groupid=groupid;
                printf("请输入你要发送的消息:\n");
                scanf("%s",m->content);
                while(getchar()!='\n');
                TcpClinetSend(c,m,sizeof(Msg));
                TcpClinetRecv(c,m,sizeof(Msg));
                if(m->operationflag==152)
                {
                    printf("发送成功\n");
                }
                else if(m->operationflag==1520)
                {
                    printf("你已被禁言\n");
                }
                else
                {
                    printf("发送失败\n");
                }
                break;
            case 3:
                memset(m,0,sizeof(Msg));
                m->operationflag=53;
                m->serial=a->serial;
                strcpy(m->myname,a->myname);
                m->mynameid=a->mynameid;
                m->groupid=groupid;
                TcpClinetSend(c,m,sizeof(Msg));
                TcpClinetRecv(c,m,sizeof(Msg));
                if(m->operationflag==153)
                {
                    int num=m->numflag;
                    if(num==0)
                    {
                        printf("暂无群聊消息\n");
                    }
                    for(int i=0;i<num;i++)
                    {
                        TcpClinetRecv(c,m,sizeof(Msg));
                        printf("%s %d :%s\n",m->toname,m->tonameid,m->content);
                    }
                }
                break;
            case 4:
            
                memset(m,0,sizeof(Msg));
                m->operationflag=54;
                m->serial=a->serial;
                m->mynameid=a->mynameid;
                m->groupid=groupid;
                strcpy(m->myname,a->myname);
                printf("请输入文件路径:\n");
                FMsg file;
                scanf("%s",file.filename);
                FILE *fd=fopen(file.filename,"rb");
                if(fd==NULL)
                {
                    printf("文件不存在\n");
                    break;
                }
                else
                {
                    TcpClinetSend(c,m,sizeof(Msg));
                    fseek(fd,0,SEEK_END);
                    file.size=ftell(fd);
                    fseek(fd,0,SEEK_SET);
                    fread(file.file,1,file.size,fd);
                    fclose(fd);
                    printf("%s\n",file.file);
                    TcpClinetSend(c,&file,sizeof(FMsg));
                }
                TcpClinetRecv(c,m,sizeof(Msg));
                if(m->operationflag==154)
                {
                    printf("上传成功\n");
                }
                break;
            case 5:
                memset(m,0,sizeof(Msg));
                m->operationflag=55;
                m->groupid=groupid;
                TcpClinetSend(c,m,sizeof(Msg));
                TcpClinetRecv(c,m,sizeof(Msg));
                if(m->operationflag==155)
                {
                    int num=m->numflag;
                    if(num==0)
                    {
                        printf("没有文件\n");
                        break;
                    }
                    for(int i=0;i<num;i++)
                    {
                        TcpClinetRecv(c,m,sizeof(Msg));
                        printf("文件序号\t上传人名字\t上传人ID\t文件名字\t文件大小\n");
                        printf("%d\t\t%s\t\t%d\t\t%s\t\t%d\n",m->serial,m->toname,m->tonameid,m->filename,m->filesize);
                    }
                    printf("请输入要下载的文件序号:");
                    scanf("%d",&m->operationflag);
                    while(getchar()!='\n');
                    TcpClinetSend(c,m,sizeof(Msg));
                    TcpClinetRecv(c,m,sizeof(Msg));
                    if(m->operationflag!=1551)
                    {
                        printf("选择有误\n");
                        break;
                    }
                    FILE *fd=fopen(m->filename,"wb");
                    fwrite(m->content,m->filesize,1,fd);
                    printf("%d %d %s\n",m->operationflag,m->filesize,m->filename);
                    printf("%s\n",m->content);
                    printf("下载完成\n");
                    fclose(fd);
                }
                break;
            case 6:
                memset(m,0,sizeof(Msg));
                m->operationflag=56;
                m->serial=a->serial;
                m->mynameid=a->mynameid;
                m->groupid=groupid;
                printf("请输入你要禁言人的ID:\n");
                scanf("%d",&m->tonameid);
                if(m->tonameid==a->mynameid)
                {
                    printf("不能禁言自己\n");
                    break;
                }
                while(getchar()!='\n');
                TcpClinetSend(c,m,sizeof(Msg));
                TcpClinetRecv(c,m,sizeof(Msg));
                if(m->operationflag==156)
                {
                    printf("禁言成功\n");
                }
                if(m->operationflag==1561)
                {
                    printf("该用户不是群成员\n");
                }
                if(m->operationflag==1562)
                {
                    printf("权限不够\n");
                }
                if(m->operationflag==1563)
                {
                    printf("无此权限\n");
                }
                break;
            case 7:
                memset(m,0,sizeof(Msg));
                m->operationflag=57;
                m->serial=a->serial;
                m->mynameid=a->mynameid;
                m->groupid=groupid;
                printf("请输入你要解禁人ID:\n");
                scanf("%d",&m->tonameid);
                if(m->tonameid==a->mynameid)
                {
                    printf("非法解禁\n");
                    break;
                }
                while(getchar()!='\n');
                TcpClinetSend(c,m,sizeof(Msg));
                TcpClinetRecv(c,m,sizeof(Msg));
                if(m->operationflag==157)
                {
                    printf("解除禁言成功\n");
                }
                if(m->operationflag==1571)
                {
                    printf("该用户不是群成员\n");
                }
                if(m->operationflag==1572)
                {
                    printf("权限不够\n");
                }
                if(m->operationflag==1573)
                {
                    printf("无此权限\n");
                }
                break;
            case 8:
                memset(m,0,sizeof(Msg));
                m->operationflag=58;
                m->serial=a->serial;
                m->mynameid=a->mynameid;
                strcpy(m->myname,a->myname);
                m->groupid=groupid;
                printf(" 请输入你要添加的好友ID:\n");
                scanf("%d",&m->tonameid);
                while(getchar()!='\n');
                TcpClinetSend(c,m,sizeof(Msg));
                TcpClinetRecv(c,m,sizeof(Msg));
                if(m->operationflag==158)
                {
                    printf("等待对方同意\n");
                }
                else if(m->operationflag==1581)
                {
                    printf("对方不是你好友\n");
                }
                break;
            case 9:
                memset(m,0,sizeof(Msg));
                m->operationflag=59;
                m->serial=a->serial;
                m->mynameid=a->mynameid;
                m->groupid=groupid;
                printf("请输入你要设置管理员的ID:\n");
                scanf("%d",&m->tonameid);
                if(m->tonameid==a->mynameid)
                {
                    printf("不能设置自己为管理员\n");
                    break;
                }
                while(getchar()!='\n');
                TcpClinetSend(c,m,sizeof(Msg));
                TcpClinetRecv(c,m,sizeof(Msg));
                if(m->operationflag==159)
                {
                    printf("设置成功\n");

                }
                if(m->operationflag==1591)
                {
                    printf("你无此权限\n");
                }
                if(m->operationflag==1592)
                {
                    printf("群聊无此人\n");
                }
                break;
            case 10:
                memset(m,0,sizeof(Msg));
                m->operationflag=60;
                m->mynameid=a->mynameid;
                m->groupid=groupid;
                TcpClinetSend(c,m,sizeof(Msg));
                TcpClinetRecv(c,m,sizeof(Msg));
                if(m->operationflag==1600)
                {
                    printf("你无此权限\n");
                }
                if(m->operationflag==160)
                {
                    printf("解散成功\n");
                    return;
                }
                break;
            case 11:
                memset(m,0,sizeof(Msg));
                m->operationflag=61;
                m->mynameid=a->mynameid;
                m->serial=a->serial;
                strcpy(m->myname,a->myname);
                m->groupid=groupid;
                TcpClinetSend(c,m,sizeof(Msg));
                TcpClinetRecv(c,m,sizeof(Msg));
                if(m->operationflag==161)
                {
                    printf("退群成功\n");
                    return;
                }
                if(m->operationflag==1610)
                {
                    printf("请先转让群聊\n");
                }
                break;
            case 12:
                memset(m,0,sizeof(Msg));
                m->operationflag=62;
                m->mynameid=a->mynameid;
                m->serial=a->serial;
                m->groupid=groupid;
                printf("请输入你要转让人ID:\n");
                scanf("%d",&m->tonameid);
                while(getchar()!='\n');
                TcpClinetSend(c,m,sizeof(Msg));
                TcpClinetRecv(c,m,sizeof(Msg));
                if(m->operationflag==162)
                {
                    printf("转让成功\n");

                }
                if(m->operationflag==1621)
                {
                    printf("你无此权限\n");
                }
                if(m->operationflag==1622)
                {
                    printf("群聊无此人\n");
                }
                break;
            case 13:
                memset(m,0,sizeof(Msg));
                m->operationflag=63;
                m->mynameid=a->mynameid;
                m->serial=a->serial;
                m->groupid=groupid;
                printf("请输入你要踢出群聊人ID:\n");
                scanf("%d",&m->tonameid);
                while(getchar()!='\n');
                if(m->tonameid==a->mynameid)
                {
                    printf("非法操作\n");
                }
                TcpClinetSend(c,m,sizeof(Msg));
                TcpClinetRecv(c,m,sizeof(Msg));
                if(m->operationflag==163)
                {
                    printf("踢出成功\n");
                }
                if(m->operationflag==1631)
                {
                    printf("该用户不是群成员\n");
                }
                if(m->operationflag==1632)
                {
                    printf("权限不够\n");
                }
                if(m->operationflag==1633)
                {
                    printf("无此权限\n");
                }
                break;
            case 14:
                return;
                break;
            default:
                printf("输入错误，请重新输入\n");
                break;    
        }
    }
}

void Group(TcpC *c, Msg *m,Admin *a)
{
    while(1)
    {
        printf("**********************\n");
        printf("* 1.查看我的群聊列表 *\n");            //31 ------
        printf("* 2.查看我管理的群聊 *\n");           //32      ------
        printf("* 3.进入群聊         *\n");                     //33  
        printf("* 4.创建群聊         *\n");                 //34    -------
        printf("* 5.查看通知         *\n");                  //35  ------
        printf("* 6.返回上一级       *\n");   
        printf("**********************\n");           
        printf("请输入你的选择:\n");
        int choice=0;
        scanf("%d",&choice);
        while(getchar()!='\n');
        switch(choice)
        {
        case 1:
            memset(m,0,sizeof(Msg));
            m->operationflag=31;
            m->mynameid=a->mynameid;
            m->serial=a->serial;
            TcpClinetSend(c,m,sizeof(Msg));
            TcpClinetRecv(c,m,sizeof(Msg));
            if(m->operationflag==131)
            {
                int num=m->numflag;
                if(num==0)
                {
                    printf("暂无群聊列表\n");
                }
                for(int i=0;i<num;i++)
                {
                    TcpClinetRecv(c,m,sizeof(Msg));
                    printf("群聊名字:%s  群聊ID:%d\n",m->group,m->groupid);
                }
            }
            break;
        case 2:
            memset(m,0,sizeof(Msg));
            m->operationflag=32;
            m->mynameid=a->mynameid;
            m->serial=a->serial;
            TcpClinetSend(c,m,sizeof(Msg));
            TcpClinetRecv(c,m,sizeof(Msg));
            if(m->operationflag==132)
            {
                int num=m->numflag;
                if(num==0)
                {
                    printf("暂无群聊列表\n");
                }
                for(int i=0;i<num;i++)
                {
                    TcpClinetRecv(c,m,sizeof(Msg));
                    printf("群聊名字:%s  群聊ID:%d\n",m->group,m->groupid);
                }
            }
            break;
        case 3:
            GroupSetting(c,m,a);
            break;
        case 4:
            memset(m,0,sizeof(Msg));
            m->operationflag=34;
            m->serial=a->serial;
            m->mynameid=a->mynameid;
            strcpy(m->myname,a->myname);
            printf("请为你的群聊命名:\n");
            scanf("%s",m->content);
            while(getchar()!='\n');
            char temp[10]={0};
            strcpy(temp,m->content);
            TcpClinetSend(c,m,sizeof(Msg));
            TcpClinetRecv(c,m,sizeof(Msg));
            if(m->operationflag==134)
            {
                printf("群聊创建成功\n");
                printf("群聊名字:%s  群聊ID:%d\n",temp,m->tonameid);
            }
            break;
        case 5:
            memset(m,0,sizeof(Msg));
            m->operationflag=35;
            m->serial=a->serial;
            m->mynameid=a->mynameid;
            strcpy(m->myname,a->myname);
            TcpClinetSend(c,m,sizeof(Msg));
            TcpClinetRecv(c,m,sizeof(Msg));
            if(m->operationflag==135)
            {
                int num=m->numflag;
                if(num==0)
                {
                    printf("暂无群聊邀请\n");
                }
                for(int i=0;i<num;i++)
                {
                    TcpClinetRecv(c,m,sizeof(Msg));
                    printf("%s\t\t%d\n",m->group,m->groupid);
                    printf("申请你入群\n");
                    while(1)
                    {
                        printf("1.同意\n");
                        printf("2.不同意\n");
                        int choice=0;
                        scanf("%d",&choice);
                        while(getchar()!='\n');
                        if(choice==1)
                        {
                            m->operationflag=1351;
                            TcpClinetSend(c,m,sizeof(Msg));
                            TcpClinetRecv(c,m,sizeof(Msg));
                            printf("%d\n",m->operationflag);
                            if(m->operationflag==13511)
                            {
                                printf("入群成功\n");
                            }
                            break;
                        }
                        else if(choice==2)
                        {
                            m->operationflag=1350;
                            TcpClinetSend(c,m,sizeof(Msg));
                            TcpClinetRecv(c,m,sizeof(Msg));
                            if(m->operationflag!=13511)
                            {
                                printf("已拒绝\n");
                            }
                            break;
                        }
                        else
                            printf("输入错误，请重新输入！\n");
                    }
                }
            }

            break;
        case 6:
            return;
            break;
        default:
            printf("输入错误，请重新输入！\n");
            break;
        }
    }
}


int Set(TcpC *c, Msg *m,Admin *a)
{
    while(1)
    {
        printf("******************\n");
        printf("* 1.修改密码     *\n");                  //41
        printf("* 2.修改账户名字 *\n");                //42
        printf("* 3.在线隐身设置 *\n");               //43
        printf("* 4.退出登录     *\n");                   //44
        printf("* 5.返回上一级   *\n");                //45
        printf("******************\n");
        printf("请输入你的选择:\n");
        int choice=0;
        scanf("%d",&choice);
        while(getchar()!='\n');
        switch(choice)
        {
        case 1:
            char temp[10];
            printf("请输入旧密码:\n");
            scanf("%s",temp);
            while(getchar()!='\n');
            if(strcmp(temp,a->password)!=0)
            {
                printf("密码错误\n");
                break;
            }
            memset(m,0,sizeof(Msg));
            m->operationflag=41;
            m->serial=a->serial;
            printf("请输入新密码:\n");
            scanf("%s",m->password);
            while(getchar()!='\n');
            TcpClinetSend(c,m,sizeof(Msg));
            TcpClinetRecv(c,m,sizeof(Msg));
            if(m->operationflag==141)
            {
                printf("修改成功\n");
            }
            break;
        case 2:
            memset(m,0,sizeof(Msg));
            m->operationflag=42;
            m->serial=a->serial;
            printf("请输入新的账户名:\n");
            scanf("%s",m->myname);
            while(getchar()!='\n');
            TcpClinetSend(c,m,sizeof(Msg));
            TcpClinetRecv(c,m,sizeof(Msg));
            if(m->operationflag==142)
            {
                printf("修改成功\n");
            }
            break;
        case 3:
            memset(m,0,sizeof(Msg));
            m->operationflag=43;
            m->mynameid=a->mynameid;
            while(1)
            {
                int temp=0;
                printf("1.在线\n");
                printf("2.隐身\n");
                printf("请输入:\n");
                scanf("%d",&temp);
                while(getchar()!='\n');
                if(temp==1)
                {
                    m->operationflag=1;
                    break;
                }
                else if(temp==2)
                {
                    m->operationflag=2;
                    break;
                }
                else
                {
                    printf("输入错误，请重新输入！\n");
                }
            }
            TcpClinetSend(c,m,sizeof(Msg));
            TcpClinetRecv(c,m,sizeof(Msg));
            if(m->operationflag==1431)
            {
                printf("当前状态已修改为在线\n");
            }
            else if(m->operationflag==1432)
            {
                printf("当前状态已修改为离线\n");
            }
            else
            {
                printf("error\n");
            }
            break;
        case 4:
            memset(m,0,sizeof(Msg));
            m->operationflag=44;
            m->mynameid=a->mynameid;
            TcpClinetSend(c,m,sizeof(Msg));
            TcpClinetRecv(c,m,sizeof(Msg));
            if(m->operationflag==144)
            {
                printf("退出成功\n");
            }
            else
            {
                printf("退出失败\n");
            }
            return false;
            break;
        case 5:
            return true;
            break;
        default:
            printf("输入错误，请重新输入！\n");
            break;
        }
    }
}


void Interface(TcpC *c, Msg *m,Admin *a)
{

    while(1)
    {
        printf("**********\n");
        printf("* 1.好友 *\n");                    //10
        printf("* 2.群聊 *\n");                     //20
        printf("* 3.设置 *\n");                       //30
        printf("**********\n");
        printf("请输入你的选择:\n");
        int choice=0;
        scanf("%d",&choice);
        while(getchar()!='\n');
        switch(choice)
        {
        case 1:
            Friends(c,m,a);
            break;
        case 2:
            Group(c,m,a);
            break;
        case 3:
            if(Set(c,m,a)==false)
                return;
            break;
        default:
            printf("输入错误，请重新输入！\n");
            break;
        }
    }
}